package ModelLayer;

import java.util.HashMap;

public class LoginContainer
{
	private HashMap<String, String> logins;
	private HashMap<String, String> admins;
	private static LoginContainer instance;

	private LoginContainer()
	{
		logins = new HashMap<String, String>();
		admins = new HashMap<String, String>();
		addLogins();
	}

	public static LoginContainer getInstance()
	{
		if (instance == null)
		{
			instance = new LoginContainer();
		}
		return instance;
	}

	public int checkPass(String user,String pass)
	{
		int check = 0;
		try{
		if(logins.get(user).equals(pass))
		{
			check = 1;
		}
		else if(admins.get(user).equals(pass))
		{
			check = 2;
		}}
		catch(NullPointerException e){}
		return check;
	}

	public String addLogin(String user, String pass)
	{
		String rtn;
		if (!logins.containsKey(user))
		{
			logins.put(user, pass);
			rtn = user + " has been created";
		}
		else
		{
			rtn = user + " already exists";
		}
		return rtn;
	}

	private void addLogins()
	{
		logins.put("egon1", "sven1");
		logins.put("boss1", "boss1");
		logins.put("egon2", "sven2");
		logins.put("boss2", "boss2");
		logins.put("egon3", "sven3");
		logins.put("boss3", "boss3");
		logins.put("1", "1");
		admins.put("2", "2");
	}
}
